<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>成本预警设置</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>成本预警</label>
                        <div class="layui-input-block">
                            <select id="is_yu" name="is_yu" lay-filter="is_yu">
                                <option value="是">是</option>
                                <option value="否" selected>否</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-hide yuinfo">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>材料费占比阈值(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_cai" name="yu_cai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>劳务人工费占比阈值(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_lao" name="yu_lao" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>机械租赁费占比阈值(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_zu" name="yu_zu" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>专业分包费占比阈值(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_fen" name="yu_fen" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>其他费占比阈值(%)</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_qi" name="yu_qi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">当前合计比例</label>
                            <div class="layui-input-block">
                                <input type="number" id="yu_heji" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>预警通知对象</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=yuer&type=user&single=2','770px','490px');"></div>
                                    <div class="tanxiannei" id="yuer"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=yuer&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                                <div id="yuer_tanerror" class="tanerrormsg"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            yu_cai: {required: true},
            yu_lao: {required: true},
            yu_zu: {required: true},
            yu_fen: {required: true},
            yu_qi: {required: true},
        },
        messages:{
            yu_cai: {required: "请输入"},
            yu_lao: {required: "请输入"},
            yu_zu: {required: "请输入"},
            yu_fen: {required: "请输入"},
            yu_qi: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_yu,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $('#name').val(data.name);
                $('#is_yu').val(data.is_yu);
                $('#yu_cai').val(data.yu_cai);
                $('#yu_lao').val(data.yu_lao);
                $('#yu_zu').val(data.yu_zu);
                $('#yu_fen').val(data.yu_fen);
                $('#yu_qi').val(data.yu_qi);

                if(data.yuer_info){
                    if(data.yuer_info.length > 0){
                        tan_tags_init('#yuer', data.yuer_info);
                    }
                }

                if(data.is_yu == '是'){
                    $(".yuinfo").removeClass('layui-hide');
                }

                jisuanheji()
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(is_yu)', function(data){
            if(data.value == '是'){
                $(".yuinfo").removeClass('layui-hide');
            }else{
                $(".yuinfo").addClass('layui-hide');
            }
            render_from();
        });


        form.on('submit(add)', function(data){
            data.field.yuer = tan_tags_getvalue("#yuer", 'user');
            var validRes = $("#commentForm").valid();

            if(data.field.is_yu == '是'){
                if(!data.field.yuer){
                    $("#yuer").parents('.tanxian').addClass('tanerror');
                    $('#yuer_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#yuer").parents('.tanxian').removeClass('tanerror');
                    $('#yuer_tanerror').text('');
                }

            }

            if(!validRes){return false;}

            data = parseMoney(data);
            data.field.id = param_id;
            facade.ajax({url: ask_engin_yu, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


    $("#yu_cai,#yu_lao,#yu_zu,#yu_fen,#yu_qi").on('input propertychange',function () {
        jisuanheji();
    });

    function jisuanheji() {
        var yu_cai = parseFloat($("#yu_cai").val()) || 0;
        var yu_lao = parseFloat($("#yu_lao").val()) || 0;
        var yu_zu = parseFloat($("#yu_zu").val()) || 0;
        var yu_fen = parseFloat($("#yu_fen").val()) || 0;
        var yu_qi = parseFloat($("#yu_qi").val()) || 0;
        var yu_heji = parseFloat(yu_cai) + parseFloat(yu_lao) + parseFloat(yu_zu) + parseFloat(yu_fen) + parseFloat(yu_qi);

        $("#yu_heji").val(parseFormatNum(yu_heji,2))
    }






</script>
</body>
</html>
